// pages/index/decorcompany/geomantic.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    winHeight: "", //窗口高度
    currentTab: 0, //预设当前项的值
    scrollLeft: 0, //tab标题的滚动条位置
    // tab切换
    toView: '',
    city: '',
    cityid: '',
    proviceid: '',
    land_page: '',
    polist: [{
      "id": "1",
      "name": "动静线",
      "simpletitle": "本户型的动静线没有交叉，布局很理想，私密性能得到很好的保证。",
      "single": 56,
      "sum": 62,
      "otherdesc": [{
        "otxt": "室内的动静线最好不要交叉，因为动静线交叉穿越，不利于客/餐厅内家具的布置和使用，也影响了休息区的私密性和安静。"
      }],
      "mask": [{
        "masktitle": "什么是动静线？",
        "tests": [{
          "text": "在选择户型的时候，我们一定要尽量避免动线交叉问题。那什么是动线呢？"
        }, {
          "text": "动线是指人们在户内活动的路线，动线流畅与否会影响到居住的品质。户内主要动线有三类，分别是居住动线、家务动线、来客动线。"
        }, {
          "text": "而差的动线，各条动线之间有交叉，比如：进厨房要穿过客厅，进卧室要穿过客厅，进餐厅要穿过客厅，客厅都成公共走廊了，另外进生活阳台要穿过主卧等等。这样的户型在居住时会给人带来很大的不便。"
        }]
      }]
    }, {
      "id": "2",
      "name": "动静分区",
      "simpletitle": "本户型动静分区非常合理，静区动区是完全分开的，私密性极佳。",
      "single": 40,
      "sum": 45,
      "otherdesc": [{
        "otxt": "动静区分开才能保障居室主人的日常生活流通顺畅，让休息的人能安心休息、走动娱乐的人可以放心活动，互不干扰。"
      }, {
        "otxt": "而静区主要供居住者休息，相对比较安静，应当尽量布置在户型内侧，比如：卧室、书房、主卫等。"
      }],
      "mask": [{
        "masktitle": "什么是动静分区？",
        "tests": [{
          "text": "动区是人们活动较为频繁的区域，应该靠近入户门设置，比如：客厅、餐厅、厨房、次卫等。"
        }, {
          "text": "动线是指人们在户内活动的路线，动线流畅与否会影响到居住的品质。户内主要动线有三类，分别是居住动线、家务动线、来客动线。"
        }, {
          "text": "而差的动线，各条动线之间有交叉，比如：进厨房要穿过客厅，进卧室要穿过客厅，进餐厅要穿过客厅，客厅都成公共走廊了，另外进生活阳台要穿过主卧等等。这样的户型在居住时会给人带来很大的不便。"
        }]
      }]
    }, {
      "id": "3",
      "name": "采光透风",
      "simpletitle": "本户型是邻侧采光通风，属于间接通风，通风一般",
      "single": 20,
      "sum": 45,
      "otherdesc": [{
        "otxt": "一般来说，比较方正的户型具有良好的通透性能。进深过大，开间过小，则会影响户型的采光和通风，让房间显得比较暗；而进深偏小，开间过大，则不利于房间保温，浪费能源，北方尤其如此。"
      }, {
        "otxt": "比较方正的户型能做到采光通风与保温两者间的平衡。"
      }, {
        "otxt": "另外，厨房和厕所是湿气比较重的两个区域，要尽量做到独立采光通风，也就是避免“暗厨”和“暗卫”"
      }],
      "mask": [{
        "masktitle": "什么是采光透风？",
        "tests": [{
          "text": "首先要求户型比较方正；"
        }, {
          "text": "其次户型最好有两面可以采光和通风，相对两面采光通风最佳（如南北、东西），"
        }, {
          "text": "第三是相邻两面采光（如东和南、南和西、西和北等），而只有一面采光通风效果最差。"
        }]
      }]
    }]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this
    var polist = that.data.polist
    var list = polist[0].mask
    // 获取tab切换时的窗口高度
    wx.getSystemInfo({
      success: function(res) {
        var clientHeight = res.windowHeight,
          clientWidth = res.windowWidth,
          rpxR = 750 / clientWidth;
        var calc = clientHeight * rpxR - 150;
        console.log(calc)
        that.setData({
          winHeight: calc
        });
      }
    });
    that.setData({
        polist: polist,
        polists: list
    })
    
  },
  //查看
  getViewdivination: function(e) {
    var that = this
    wx.request({
      url: app.apiUrl('c=zhaobiao/index&a=view_divination'),
      data: {},
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      method: "GET",
      success: function(res) {
        console.log(res.data)
        var land_page = res.data.datas.landing_page
        that.setData({
          land_page: land_page
        })
      },
      fail: function(res) {
        console.log('请求失败', res.data)
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  //城市选择
  choosecity: function(e) {
    wx: wx.navigateTo({
      url: '../public/custom/cucity',
    })
  },
  settime: function() {
    var that = this
    setTimeout(function() {
      that.setData({
        alertmess: false
      })
    }, 2000)
  },

  //form表单提交
  formSubmit: function(e) {
    var that = this
    var city = e.detail.value.city;
    var aleaname = e.detail.value.rqname;
    var area = e.detail.value.area;
    var tele = e.detail.value.tele;
    var cityid = that.data.cityid;
    var proviceid = that.data.proviceid;
    var city = that.data.city;
    var land_page = that.data.land_page
    var id = 2;
    var title = '申请资料提交成功'
    var tsmall = '恭喜您，申请资料成功，我们将尽快与您联系!';
    var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/;

    if (city == '') {
      that.setData({
        alertmess: true,
        message: '请选择城市！'
      })
      that.settime()
      return false;
    } else if (aleaname == '') {
      that.setData({
        alertmess: true,
        message: '请填写小区名称！'
      })
      that.settime()
    } else if (area == '') {
      that.setData({
        alertmess: true,
        message: '请填写房屋面积！'
      })
      that.settime()
    } else if (tele == '') {
      that.setData({
        alertmess: true,
        message: '请输入手机号码！'
      })
      that.settime()
      return false;
    } else if (tele.length != 11) {
      that.setData({
        alertmess: true,
        message: '请重新输入号码！'
      })
      that.settime()
    } else if (!myreg.test(tele)) {
      that.setData({
        alertmess: true,
        message: '手机号错误，请重新输入！'
      })
      that.settime()
    } else {
      wx.request({
        url: app.apiUrl('c=zhaobiao/index&a=submit_divination'),
        data: {
          phone: tele,
          address: aleaname,
          acreage: area,
          province: proviceid,
          city: cityid,
          landing_page: land_page
        },
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        method: "POST",
        success: function(res) {
          console.log(res.data)
          var code = res.data.code
          var message = res.data.error
          if (code == 200) {
            wx: wx.navigateTo({
              url: '../free/applysuccess?data=' + [id, title, tsmall],
            })
          }
          else if (code == 400) {
            that.setData({
              alertmess: true,
              message: message
            })
            that.settime()
          }
        },
        fail: function(res) {
          console.log('请求失败', res.data)
        }
      })
      // wx: wx.navigateTo({
      //   url: '../free/applysuccess?data=' + [id, title, tsmall],
      // })
    }

    console.log('form发生了submit事件，携带数据为：', e.detail.value)
  },

  // 点击标题切换当前页时改变样式
  swichNav: function(e) {
    var that = this
    var cur = e.target.dataset.current;
    var polist = that.data.polist
    var list = polist[cur].mask
    console.log(polist)
    if (this.data.currentTaB == cur) {
      return false;
    } else {
      this.setData({
        currentTab: cur
      })
    }
    that.setData({
      polists: list
    })
    console.log(cur)
  },
  switchTab: function(e) {
    var that = this
    var index = e.detail.current
    var polist = that.data.polist
    var list = polist[index].mask
    that.setData({
      currentTab: e.detail.current,
      polists: list
    });
    that.checkCor();
  },
  //判断当前滚动超过一屏时，设置tab标题滚动条。
  checkCor: function() {
    if (this.data.currentTab > 4) {
      this.setData({
        scrollLeft: 300
      })
    } else {
      this.setData({
        scrollLeft: 0
      })
    }
  },
  //提示框
  choosetips: function(e) {
    this.setData({
      modeltips: true
    })
  },
  close: function(e) {
    this.setData({
      modeltips: false
    })
  },

  footerTap: app.footerTap,
})